﻿
namespace Service
{
    using Data.Repository;
    using System.Linq;
	using System.Collections.Generic;

    public class ProductRatingService : IProductRatingService
    {
        private IProductRatingRepository _productRatingRepository;

        #region IProductRatingService Members

        /// <summary>
        /// create new ProductRating 
        /// </summary>
        /// <param name="theNewProductRating">the new ProductRating instance</param>
        /// <returns>the new ProductRating's ID</returns>
        public int CreateNewProductRating(Data.Entity.ProductRating theNewProductRating)
        {
            if (theNewProductRating == null)
            {
                return 0;
            }

            if (_productRatingRepository == null)
            {
                _productRatingRepository = new ProductRatingRepository();
            }

            return _productRatingRepository.CreateNewProductRating(theNewProductRating);
        }

        public IList<Data.Entity.ProductRating> GetProductRatingByProduct(int productID)
        {
            if (productID <= 0)
            {
                return null;
            }

            if (_productRatingRepository == null)
            {
                _productRatingRepository = new ProductRatingRepository();
            }

            return _productRatingRepository.GetProductRatingByProduct(productID);
        }

        #endregion
    }
}
